package com.hotel.po.controller;

import com.github.pagehelper.PageInfo;
import com.hotel.common.utils.Result;
import com.hotel.po.service.SeasonPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/po/season-prices")
public class SeasonPriceController {

    @Autowired
    private SeasonPriceService service;

    @GetMapping
    public Result<java.util.Map<String, Object>> list(@RequestParam(name = "roomId", required = false) Long roomId,
                                                      @RequestParam(name = "page", defaultValue = "1") int page,
                                                      @RequestParam(name = "size", defaultValue = "10") int size) {
        PageInfo<java.util.Map<String, String>> pageInfo = service.list(roomId, page, size);
        java.util.HashMap<String, Object> resp = new java.util.HashMap<>();
        resp.put("list", pageInfo.getList());
        resp.put("total", pageInfo.getTotal());
        return Result.success(resp);
    }

    @PostMapping
    public Result<Long> create(@RequestBody Map<String, Object> body) { return Result.success(service.create(body)); }

    @PutMapping
    public Result<Void> update(@RequestBody Map<String, Object> body) { service.update(body); return Result.success(); }

    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable("id") Long id) { service.delete(id); return Result.success(); }
}


